package com.crm.kz.menu;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.crm.kz.R;
import com.crm.kz.common.AutoUpdater;
import com.crm.kz.common.BaseFragment;
import com.crm.kz.common.HttpCellBack;
import com.crm.kz.common.HttpUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Fragment2 extends BaseFragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.frament_2, container, false);
//        TextView clientView = view.findViewById(R.id.select_client);
        LinearLayout selectLayoutClient = view.findViewById(R.id.selectLayoutClient);
        selectLayoutClient.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View LayoutClient) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                    if (!Environment.isExternalStorageManager()) {
                        Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
                        intent.setData(Uri.parse("package:com.crm.kz" ));
//                        startActivityForResult(intent, 1024);
                    }
                }
//                AutoUpdater au = new AutoUpdater(getContext());
//                au.DownloadApk();
                HttpUtils.androidUpdate(getContext().getApplicationContext());
//                HttpUtils.postObject("http://192.168.0.103:8100/system/test",new HttpCellBack(){
//                    @Override
//                    public void cellback(Map<String,Object>map) {
//                        TextView tv = (TextView) view.findViewById(R.id.select_client);
//                        System.out.println(map.toString()+(String) map.get("tx"));
//                        tv.setText((String) map.get("tx"));
//                    }
//                });

                Toast.makeText(getContext(), "onClientViewClick", Toast.LENGTH_SHORT).show();
            }
        });
        return view;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    public static Fragment2 newInstance() {
        Fragment2 fragment2 = new Fragment2();
        return fragment2;
    }

}
